<template>
	<view class="posiab width1000">
		<image mode="widthFix" :src="imgurl+'userimg.png'" class="image  "></image>
		<image mode="widthFix" src="/static/userbottom.png" class="image posiab bottom-20"></image>
		<view class="con posire ">
			<view class=" width92vw flex-ju-a color666 bottom50 size24 posiab zindex111">
				<view @click="navto('behead')" class="flex-col flex-ju-c">
					<image mode="widthFix" src="/static/yizhan.png" class="image mb5 width72"></image>
					<view>我的已斩</view>
				</view>
				<view @click="navto('note')" class="flex-col flex-ju-c">
					<image mode="widthFix" src="/static/ubiji.png" class="image mb5 width72"></image>
					<view>我的笔记</view>
				</view>
				<view @click="navto('collect')" class="flex-col flex-ju-c">
					<image mode="widthFix" src="/static/ucangs.png" class="image mb5 width72"></image>
					<view>我的收藏</view>
				</view>
				<view @click="navto('course')" class="flex-col flex-ju-c">
					<image mode="widthFix" src="/static/kke.png" class="image mb5 width72"></image>
					<view>我的课程</view>
				</view>
			</view>
		</view>
	</view>

	<view class="con">
		<view class="width92vw pt80  ">
			<view :style="{paddingTop:shh+'px'}"></view>
			<view v-if="user"  class="flex-ju-b posire">
				<view class="flex-a-i">
					<image
						:src="user.avatarUrl?user.avatarUrl:'https://thirdwx.qlogo.cn/mmopen/vi_32/POgEwh4mIHO4nibH0KlMECNjjGxQUq24ZEaGT4poC6icRiccVGKSyXwibcPq4BWmiaIGuG1icwxaQX6grC9VemZoJ8rg/132'"
						class="wh130-130 ra130 mr20"></image>
					<view>
						<view class="flex-a-i size36 color0F172B bold400">
							{{user.nickName?user.nickName:'微信用户'}}
						</view>
						<view class="size24 mt20 color666">UID:{{user.id}}</view>
					</view>
				</view>
				<image @click="upuser" mode="widthFix" src="/static/edit.png" class="width72 flex "></image>
			</view>
			<view v-else @click="uplogin" class="flex-a-i">
				<image
					src="https://thirdwx.qlogo.cn/mmopen/vi_32/POgEwh4mIHO4nibH0KlMECNjjGxQUq24ZEaGT4poC6icRiccVGKSyXwibcPq4BWmiaIGuG1icwxaQX6grC9VemZoJ8rg/132"
					class="wh130-130 ra130 mr20"></image>
				<view>
					<view class="flex-a-i size36 color0F172B bold400">
						点击登录
					</view>
				</view>
			</view>
			<view class="pt300">

				<view class="posire size28 bgfff pg30 ra30">
					<view @click="navto('/pages/agreement?type=1')" class="flex-ju-b  pb30 border-bECEDEE">
						<view class="flex-a-i ">
							<image mode="widthFix" src="/static/yingsi.png" class="width40 flex mr10"></image>
							隐私政策
						</view>
						<view>
							<image mode="widthFix" src="/static/right.png" class="width32 flex "></image>
						</view>
					</view>
					<view @click="navto('/pages/agreement?type=2')" class="flex-ju-b  mt30  ">
						<view class="flex-a-i ">
							<image mode="widthFix" src="/static/fuwu.png" class="width40 flex mr10"></image>
							服务条款
						</view>
						<view>
							<image mode="widthFix" src="/static/right.png" class="width32 flex "></image>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
	<uni-popup @change="changeup" type="bottom" ref='edituser'>
		<image mode="widthFix" :src="imgurl+'userim.png'" class="image flex posiab"></image>
		<view class="posire con pt30" :style="{paddingBottom:bhh+'px'}">
			<view class="flex-ju-b color222 size32 bold">
				<view>编辑资料</view>
				<view @click="$refs.edituser.close()">
					<uni-icons color="#999" type="closeempty" size="30"></uni-icons>
				</view>
			</view>
			<view @click="tapupimg" class="flex-ju-c posire mt50">
				<image
					:src="user.avatarUrl?user.avatarUrl:'https://thirdwx.qlogo.cn/mmopen/vi_32/POgEwh4mIHO4nibH0KlMECNjjGxQUq24ZEaGT4poC6icRiccVGKSyXwibcPq4BWmiaIGuG1icwxaQX6grC9VemZoJ8rg/132'"
					class="wh192-192 image ra160"></image>
				<view class="posiab wh50-50 ra50 bgfff flex-ju-c bottom0 ml130 borderf6f6f6">
					<image src="/static/upaizhaos.png" mode="widthFix" class="width48"></image>
				</view>
			</view>
			<view class="bgfff pg30-20 ra30 mt50">
				<view  class="flex-ju-b  pb30 border-bECEDEE">
					<view class="flex-a-i ">
						昵称
					</view>
					<view class=" text-right flex-a-i size28">
						<input class="flex1" @confirm="tapconfirm" confirm-type="done" v-model="nickName" placeholder-style="font-size:28rpx;" placeholder="输入名称"/>
						<image mode="widthFix" src="/static/right.png" class="width32 flex "></image>
					</view>
					<!-- <view class="flex-a-i">
						{{user.nickName?user.nickName:'微信用户'}}
						<image mode="widthFix" src="/static/right.png" class="width32 flex "></image>
					</view> -->
				</view>
				<view class="flex-ju-b mt30  ">
					<view class="flex-a-i ">
						UID
					</view>
					<view @click="copy(user.id)" class="flex-a-i">
						{{user.id}}
					</view>
				</view>
			</view>
			<view @click="tapout" class="bgfff flex-ju-c pg30-30 ra30 mt20">
				退出当前账户
			</view>
		</view>
	</uni-popup>

</template>

<script>
	export default {
		data() {
			return {
				code: "",
				user: "",
				nickName:""
			}
		},
		onShow() {
			if (uni.getStorageSync('user')) {
				this.user = uni.getStorageSync('user')
				this.nickName = this.user.nickName
			}
		},
		mounted() {
		
		},
		onLoad() {


		},
		methods: {
			tapconfirm(){
				this.http('/api/wxUser',{
					nickname:this.nickName
				},'put').then(resd=>{
					this.toast('修改成功')
					var user = uni.getStorageSync('user')
					user.nickName = this.nickName
					uni.setStorageSync('user',user)
					this.user.nickName = this.nickName
				})
			},
			changeup(e) {
				if (!e.show) {
					uni.showTabBar()
				}
			},
			upuser(){
				this.$refs.edituser.open()
				uni.hideTabBar()
			},
			tapupimg() {
				this.upimg(1).then(res => {
					this.http('/api/wxUser', {
						avatar: res[0]
					}, 'put').then(resd => {
						this.toast('修改成功')
						this.user.avatarUrl = res[0]
						var user = uni.getStorageSync('user')
						user.avatarUrl = res[0]
						uni.setStorageSync('user', user)
					})
				})
			},
			tapout() {
				uni.showModal({
					content: '确定要退出吗？',
					confirmColor:"#FD2F55",
					cancelColor:"#222",
					success: (res) => {
						if (res.confirm) {
							uni.setStorageSync('user', '')
							uni.reLaunch({
								url: "/pages/user/index"
							})
						}
					}
				})

			},

			uplogin() {

			

				uni.login({
					provider: 'weixin',
					success: (loginRes) => {
						this.code = loginRes.code
						this.http('/api/wx/login', {
							code: this.code
						}, 'post').then(res => {
							this.user = res.data.userDto
							uni.setStorageSync('token', 'Bearer ' + res.data.token)
							uni.setStorageSync('user', res.data.userDto)
							this.nickName = this.user.nickName
						})
					}
				});
			}
		}
	}
</script>

<style>
	page {
		background: #F6F6F6;
	}
</style>